#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import multiprocessing


def myprint(obj):
    sys.stdout.write(str(obj) + '\n')


def consumer(input_q):
    while True:
        item = input_q.get()
        if item is None:
            break
        myprint(item)
    myprint('consumer done')


def producer(sequence, output_q):
    for item in sequence:
        output_q.put(item)


if __name__ == '__main__':
    q = multiprocessing.Queue()
    cons_p = multiprocessing.Process(target=consumer, args=(q, ))
    cons_p.start()

    sequence = range(5)
    producer(sequence, q)

    q.put(None)
    cons_p.join()
